package ch6;

public class GetSecond {

	public static void main(String[] args) {
		// 第二大
		// int arrays[] = new int[] { 290, 190, 66, 3, 54, 2, 89, 45, 33, 10, 4,
		// 30, 21, 19, 22, 9, 18, 35, 47, 5, 29 };
		int arr[] = new int[] { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
		int first = 0, second = 0, count = 0;
		if (arr[0] > arr[1]) {
			first = arr[0];
			second = arr[1];
		} else if (arr[0] == arr[1]) {
			first = arr[0];
		} else {
			first = arr[1];
			second = arr[0];
		}
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] > first) {
				second = first;
				first = arr[i];
			} else if (arr[i] < first) {
				if (count == 0) {
					second = arr[i];
					count++;
					continue;
				}
				if (arr[i] > second) {
					second = arr[i];
				}
			}
		}
		if (count == 0) {
			System.out.println("不存在第二大的数");
		} else {
			System.out.println("第二大的数是" + second);
		}
	}

}
